package cn.tianyun.pethome.login.controller;

import cn.tianyun.pethome.basic.exception.BusinessException;
import cn.tianyun.pethome.basic.util.AjaxResult;
import cn.tianyun.pethome.basic.util.BaseConstants;
import cn.tianyun.pethome.login.domain.PhoneCodeVo;
import cn.tianyun.pethome.login.service.ImgCodeCreatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/imgCode")
public class ImgCodeCreatController {
    @Autowired
    private ImgCodeCreatService imgCodeCreatService;
    @GetMapping("/register/{uuid}")
    public String getImgCode(@PathVariable("uuid") String uuid){
        return  imgCodeCreatService.getImgCode(uuid, BaseConstants.ImgCode.STATE_REGISTER);
    }
    @PostMapping
    public AjaxResult register(@RequestBody PhoneCodeVo phoneCodeVo){
        try {
            imgCodeCreatService.register(phoneCodeVo);
            return AjaxResult.creat().setSuccess(true);
        }catch (BusinessException e){
            return AjaxResult.creat().setSuccess(false).setMsg(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.creat().setSuccess(false).setMsg("网络故障");
        }
    }

}
